define(["jquery","underscoreBase", "marionette", "vent" ], function(\$, _, Marionette, vent) {

	var DetailsView = Marionette.ItemView.extend({
			
			template : _.template(\$('#tpl-${domainClass}-details-form').html()),
			
			ui : {
				formPanel : 'form',
				id:'#idInput',
				saveBtn:'#saveBtn',
				deleteBtn: '#deleteBtn'
			},
		
			events : {
				'click @ui.saveBtn': 'save${capDomainClass}',
				'click @ui.deleteBtn' : 'delete${capDomainClass}',
				'keyup input' : "checkForEnter",
				'submit @ui.formPanel' : 'preventSubmit'
			},
		
			save${capDomainClass} : function(){
				
				if(this.isFormValid()){
					
					var that = this;
					
					this.setModelData();
					
					this.model.save({},{
						success: function(){
							vent.trigger('updated${capDomainClass}', that.model);
							vent.trigger('showMessage', "Success!", "${capDomainClass} successfully saved.", "success");
						},
						error: function(){
							vent.trigger('failedSave${capDomainClass}', that.model);
							vent.trigger('showMessage', "Error!", "${capDomainClass} could not be saved.");						
						}
					});
				} else {
					vent.trigger('showMessage', "Caution!", "Your entered data is invalid. Please check yur input.", "warning");						
				}
			},
		
			isFormValid : function(){
				return this.ui.id.val() != '';
			},
		
			setModelData : function(){
				this.model.set({id:this.ui.id.val()});
			},
		
			delete${capDomainClass} : function(){
			
				if(confirm("Are you sure?")) {
								
					vent.trigger('beforeDestroy${capDomainClass}', this.model);
								
					var that = this;
								
					this.model.destroy({
						success: function(model, response) {
							vent.trigger('destroyed${capDomainClass}', this.model);
							vent.trigger('showMessage', "Success!", "${capDomainClass} has been successfully deleted.", "success");
						},
						error: function(){
							vent.trigger('failedDestroy${capDomainClass}', that.model);
							vent.trigger('showMessage', "Error!", "${capDomainClass} could not be deleted.");
						}
					});
								
					this.close();
				}
			},
		
			checkForEnter : function(e) {
				
			   if(e.keyCode == 13){
				   this.saveTest();
			   }
		   },
		   
		   preventSubmit : function(e){
			   e.preventDefault();
			   return false;
		   }
		});
		
	return DetailsView;
});